home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / wtj007.zip / GLASS.ZIP / LZTEST.PAS < prev   
Pascal/Delphi Source File  |  1992-07-24  |  3KB  |  89 lines

  1. program LZTest;
  2.  
  3. { Demonstrate use of routines in LZEXPAND.DLL. }
  4.  
  5. { By Brett Glass }
  6.  
  7. { This program demonstrates the use of LZEXPAND.DLL. It
  8.   was based entirely on the behavior of existing Windows
  9.   programs, yet works reliably. }
  10.  
  11. {$X+} { Turn on Turbo Pascal's idiosyncratic null-terminated string
  12.         extensions.}
  13.  
  14. uses LZExpand, { This unit interfaces with LZEXPAND.DLL }
  15.      WinCRT,   { Display program in scrolling character window.   
  16.                  No need for fancy Windows tricks in this demo! }    
  17.      WinTypes, { Windows types, defined for Turbo Pascal }
  18.      WinProcs; { Windows APIs, defined for Turbo Pascal }
  19.  
  20. type
  21.   { Make a type for big null-terminated strings }
  22.   BigString = array [0..255] of Char;
  23.  
  24. var
  25.   src, dest, exp : BigString; { Source and destination file names}
  26.   srcHandle, destHandle : Integer; { Source and destination file handles }
  27.   ofStructSrc, ofStructDest : TOFStruct; { OpenFile structures }
  28.   lzResult : Integer; { This integer holds the results of some functions }
  29.   copyResult : Longint; { This integer holds the byte count from the copy }  
  30.  
  31. procedure FinishWinCRT;
  32.  { Bring a program written with TPW's WinCRT unit to a neat finish }
  33.  begin
  34.  Writeln('Press <Enter> to close window');
  35.  Readln;
  36.  DoneWinCrt;
  37.  end;
  38.  
  39. begin
  40. Writeln('LZEXPAND test program');
  41. Write('Enter the name of a (possibly compressed) file to copy: ');
  42. Readln(src);
  43. Write('Now enter a filename for the copy: ');
  44. Readln(dest);
  45.  
  46. { Demonstrate GETEXPANDEDNAME. Note that LZSTART doesn't need to be 
  47.   called before using this function. }
  48. lzResult := GETEXPANDEDNAME(src, exp);
  49. if lzResult < 0 then
  50.   begin
  51.   Writeln('Could not find source file');
  52.   FinishWinCRT
  53.   end
  54. else
  55.   Writeln('Expanded name of source file: ', exp);
  56.  
  57. { Now demonstrate file expansion. }
  58. lzResult := LZSTART; { Must do this before a compressed file is
  59. opened } if lzResult <> 1 then
  60.   begin
  61.   Writeln('LZSTART failed. Error code: ',lzResult);
  62.   FinishWinCRT
  63.   end;
  64. { Open the source file. The string "src" can specify either the expanded
  65.   or the unexpanded name. }
  66. srcHandle := LZOPENFILE(src,ofStructSrc,of_Read);
  67. if srcHandle < 0 then
  68.   begin
  69.   Writeln('Could not open source file.');
  70.   FinishWinCRT
  71.   end;
  72. { Open an ordinary file for output }
  73. destHandle := OpenFile(dest,ofStructDest,of_Create);
  74. if destHandle < 0 then
  75.   begin
  76.   Writeln('Could not open destination file.');
  77.   FinishWinCRT
  78.   end;
  79. copyResult := LZCOPY(srcHandle, destHandle); { Copy the file } if
  80. copyResult > 0 then
  81.  Writeln(copyResult, ' bytes in destination')
  82. else
  83.  Writeln('Copy failed; error code ', lzResult);
  84. LZCLOSE(srcHandle);
  85. _lclose(destHandle);
  86. LZDONE;
  87. FinishWinCRT;
  88. end.
  89.